// 1 基本格式
class Class1 {
    constructor(option) {
        //存放属性(简单类型),相当于构造函数的this.a=option
        this.a = option;
    }

    //复杂类型自动回放入prototype原型中,相当于构造函数的class1.prototype.fn=...
    fn() {
        console.log(this.b);
    }

    //相当于构造函数的newFun.staticMethod=...
    static staticMethod() {
        console.log("静态方法只能通过类调用")
    }

    set sa(value){
        this.a = value;
    }

    get sa() {
        return this.a;
    }
}

const obj1=new Class1('哈哈哈')
console.log('obj1',obj1)

//===================================================

// 2 属性不放入constructor中也会默认放入
class Class2 {
    constructor(option) {
        this.a = option;
    }

    b='嘻嘻嘻'

    
    fn() {
        console.log(this.b);
    }
}

const obj2 = new Class2('哈哈哈')
console.log('obj2',obj2)

//======================================================

//3  继承
class ClassFather {
    constructor(option){
        this.a=option
    }

    fatherFun(){
        console.log('父辈的函数')
    }
}

class ClassSon extends ClassFather {
    constructor(optionSon){
        //拿取父辈的属性和返回,更改其this指向,不过父辈方法是在__proto__>__proto__中
        super(optionSon)
        //子辈自已的属性
        this.b='嘻嘻嘻'
    }

    sonFun(){
        console.log('子辈自已的方法')
    }
}

const extendsObj=new ClassSon('哈哈哈')
console.log('extendsObj',extendsObj)